package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.34充电过程中上传确认数据
 * @author: GuoXiaolin
 * @date 2019/5/25 18:01
 * @Version 1.0
 * @Descibe
 */
@Slf4j
public class Csdna1_16 implements IPacking {

    private String co;          //    充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;      //    充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String card;        //    物理卡号	压缩BCD码	8Byte	16位编码
    private String money;       //    扣款金额	BIN码	4Byte	精确到小数点后两位
    private String accountMoney;//    帐户余额	BIN码	4Byte	精确到小数点后两位
    private String successIdentify;     //    成功标志	BIN码	1Byte	最高位：0：成功；1：失败   低7位：失败原因, 1:SM4密钥错误, 127:其它原因
    private String failReason; //    扣款失败原因	压缩BCD码	  2Byte	0000-成功 0001-账户余额不足 0002-套餐余额不足 0003-交易相同 0004-挂失卡 0005-车卡不匹配
    private String CcLc;        //    扣除里程	BIN码	4Byte	精确到小数点后两位
    private String SyLc;        //    剩余里程	BIN码	4Byte	精确到小数点后两位
    private String CcDl;        //    扣除电量	BIN码	4Byte	精确到小数点后两位
    private String SyDl;        //    剩余电量	BIN码	4Byte	精确到小数点后两位
    private String CcCs;        //    扣除次数	BIN码	4Byte	精确到小数点后两位
    private String SyCs;        //    剩余次数	BIN码	4Byte	精确到小数点后两位

    public Csdna1_16 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_16 setChargeIdentify(String chargeIdentify) {
        this.chargeIdentify = FieldPack.caseToBin(chargeIdentify, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());

        return this;
    }

    public Csdna1_16 setCard(String card) {
        this.card = FieldPack.caseToBCD(card, TypeIdentif.BYTE_CARD.getByteLength());
        return this;
    }

    public Csdna1_16 setMoney(double money) {
        this.money = FieldPack.decimalToHex(money, 2, TypeIdentif.BYTE_MONEY.getByteLength());
        return this;
    }

    public Csdna1_16 setAccountMoney(double accountMoney) {
        this.accountMoney =  FieldPack.decimalToHex(accountMoney, 2, TypeIdentif.BYTE_ACCOUNT_MONEY.getByteLength());
        return this;
    }

    public Csdna1_16 setSuccessIdentify(int successIdentify) {
        this.successIdentify = FieldPack.caseToSuccess(successIdentify, TypeIdentif.BYTE_SUCCESS_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_16 setFailReason(String failReason) {
        this.failReason = FieldPack.caseToBCD(failReason, TypeIdentif.BYTE_FAIL_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_16 setCcLc(double CcLc) {
        this.CcLc =  FieldPack.decimalToHex(CcLc, 2, TypeIdentif.BYTE_DEDUCTION_TIMES.getByteLength());
        return this;
    }

    public Csdna1_16 setSyLc(double SyLc) {
        this.SyLc =  FieldPack.decimalToHex(SyLc, 2, TypeIdentif.BYTE_SURPLUS_TIMES.getByteLength());
        return this;
    }

    public Csdna1_16 setCcDl(double CcDl) {
        this.CcDl =  FieldPack.decimalToHex(CcDl, 2, TypeIdentif.BYTE_DEDUCTION_TIMES.getByteLength());
        return this;
    }

    public Csdna1_16 setSyDl(double SyDl) {
        this.SyDl =  FieldPack.decimalToHex(SyDl, 2, TypeIdentif.BYTE_SURPLUS_TIMES.getByteLength());
        return this;
    }

    public Csdna1_16 setCcCs(double CcCs) {
        this.CcCs =  FieldPack.decimalToHex(CcCs, 2, TypeIdentif.BYTE_DEDUCTION_TIMES.getByteLength());
        return this;
    }

    public Csdna1_16 setSyCs(double SyCs) {
        this.SyCs =  FieldPack.decimalToHex(SyCs, 2, TypeIdentif.BYTE_SURPLUS_TIMES.getByteLength());
        return this;
    }
    @Override
    public String packing() {
        return this.co +
                this.chargeIdentify +
                this.card +
                this.money +
                this.accountMoney +
                this.successIdentify +
                this.failReason +
                this.CcLc +
                this.SyLc +
                this.CcDl +
                this.SyDl +
                this.CcCs +
                this.SyCs;
    }

    @Override
    public String toString() {
        return "Csdna1_16{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                ", card='" + card + '\'' +
                ", money='" + money + '\'' +
                ", accountMoney='" + accountMoney + '\'' +
                ", successIdentify='" + successIdentify + '\'' +
                ", failReason='" + failReason + '\'' +
                ", CcLc='" + CcLc + '\'' +
                ", SyLc='" + SyLc + '\'' +
                ", CcDl='" + CcDl + '\'' +
                ", SyDl='" + SyDl + '\'' +
                ", CcCs='" + CcCs + '\'' +
                ", SyCs='" + SyCs + '\'' +
                '}';
    }
}
